﻿$(".btn a").click(function () {
    $(this).addClass('gn_payfor_active').siblings('a').removeClass('gn_payfor_active');
    var eq = $(this).index();
    $('.gn_payfor_choose').eq(eq).css('display', 'block').siblings('.gn_payfor_choose').css('display', 'none');
    $("input[type='radio']").attr("checked", false);
});
$('.bank_list ul li').click(function () {
    selectThePlatform(this);
    $(this).addClass('cur').siblings().removeClass('cur');
});
function selectThePlatform(Obj) {
    var $radio = $(Obj).find("input[type=radio]");
    if (!$radio.is(":checked")) {
        $radio.prop("checked", true);
    }
}
$('#to_zf').click(function () {
    var that = this;
    var code = $('#text_vcode').val().trim();
    var codeLen = code.length;
    if (codeLen == 0) {
        $(that).siblings('.tishi').show();
        $(that).siblings('.tishi').text("请输入短信验证码");
    } else {
        var data = {};
        if (payid == null) {
            $(that).siblings('.tishi').show();
            $(that).siblings('.tishi').text("请先获取短信验证码");
            return;
        }
        data.PayId = payid;
        data.SmsCheckCode = code;
        $.post('/Cashie/SmsPay', data, function (result) {
            if (result.success) {
                $(that).siblings('.tishi').text("");
                $('#zf_suc').show().siblings().hide();
            } else {
                if (result.error) {
                    $(that).siblings('.tishi').text(result.error.message);
                }
            }
        });
    }
});
$('#go_bind').click(function () {
    $('.bind_box').show();
    $('.pay_box').eq(0).show().siblings('.pay_box').hide();
    $('.txt').val("");
    $(".bind_code").val("");
});
$('.close').click(function () {
    $('.bind_box').hide();
    $("#errortip").text("");
    $(".tishi").text("");
    window.location.reload();
});
$('.bind_bg').click(function () {
    $('.bind_box').hide();
    $("#errortip").text("");
});
$('.pay_box').eq(0).show().siblings('.pay_box').hide();
var txt = $('.txt').val();
var code = $('.bind_code').val();
$('#to_step2').click(function () {
    var bankCard = $('#bankCard').val().trim();
    var num = bankCard.replace(/\s/g, "");
    var numLen = num.length;
    var regBank = /^(\d{16}|\d{19})$/;
    $('#bankCardText').text(bankCard);
    if (regBank.test(bankCard)) {
        $('#stemp2').show().siblings('.pay_box').hide();
    } else {
        $('#bankCard').siblings('.tishi').text('银行卡号格式错误');
    }
})
var Token = null;
/*填写个人信息*/
$('#to_step3').click(function () {
    var name = $('#name').val().trim();
    var idCard = $('#idCard').val().trim();
    var telNum = $('#tel').val().trim();
    var regName = /^[\u4e00-\u9fa5]{2,4}$/;
    var regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    var mobileRegex = /^(((1[3456789][0-9]{1})|(15[0-9]{1}))+\d{8})$/;
    $('#bindTelNum').text(telNum);
    if (regName.test(name) && regIdNo.test(idCard) && mobileRegex.test(telNum)) {
        var data = {};
        data.ApplyId = $('#applyId').val().trim();
        data.BankNo = "gyb";
        data.AccountNo = $('#bankCard').val().trim();
        data.AccountName = name;
        data.IdentityNo = idCard;
        data.AccountType = 1;
        data.OpenBankName = '贵阳银行';
        data.OpenBankProvince = '贵州';
        data.OpenBankCity = '贵阳';
        data.MobilePhone = telNum;
        $.post('/Cashie/MemberBankCardBindApply', data, function (result) {
            if (result.success) {
                $('#bindWran').text('');
                Token = result.result.token;               
                $('#stemp3').show().siblings('.pay_box').hide();

            } else {
                if (result.error) {
                    $('#bindWran').text(result.error.message);
                }
            }
        });
    } else {
        if (!regName.test(name)) {
            $('#name').siblings('.tishi').text("姓名格式错误");
        } else {
            $('#name').siblings('.tishi').text("");
        }
        if (!regIdNo.test(idCard)) {
            $('#idCard').siblings('.tishi').text("身份证格式错误");
        } else {
            $('#idCard').siblings('.tishi').text("");
        }
        if (!mobileRegex.test(telNum)) {
            $('#tel').siblings('.tishi').text("手机号码格式错误");
        } else {
            $('#tel').siblings('.tishi').text("");
        }
    }
});
/*同意协议*/
$('#agree').click(function () {
    var that = this;
    var code = $('#code').val().trim().length;
    var checked = $('#check');
    if (code > 0 && checked.is(':checked') == true) {
        var data = {};
        data.Token = Token;
        data.SmsCheckCode = $('#code').val();
        $.post('/Cashie/MemberBankCardBind', data, function (result) {
            if (result.success) {
                $('#add_suc').show().siblings().hide();
            } else {
                if (result.error) {
                    $(that).siblings('.tishi').text(result.error.message);
                }
            }
        });

    } else {
        if (checked.is(':checked') == false) {
            checked.siblings('.tishi').text("请同意协议");
        } else {
            checked.siblings('.tishi').text("");
        }
        if (code == 0) {
            $('#code').siblings('.tishi').text("验证码不能为空");
        } else {
            $('#code').siblings('.tishi').text("");
        }
    }
});
//验证码
var wait = 60;
function time() {
    if (wait == 0) {
        $('#get_code').html("获取验证码");
        $('#get_code').removeAttr("disabled");
        wait = 60;
    } else {
        setTimeout(function () {
            time();
        }, 1000);
        $('#get_code').attr("disabled", "disabled");
        $('#get_code').html(wait + "s");
        wait--;
    }
}
var payid = null;
$("#get_code").click(function () {
    var that = this;
    var data = {};
    data.applyId = $("#applyId").val();
    data.channelId = $('#channelId').val();
    data.BankCradPayId = $('input[name=GyQuike]:checked').val();
    $.post('/Cashie/PayChannel', data, function (result) {
        if (result.success) {
            payid = result.result.payId;
        } else {
            if (result.error) {
                $(that).siblings('.tishi').text(result.error.message);
            }
        }
    });
    time();
});